
using System;
using System.Text;
using SpotifyGenNHibernate.CEN;
using NHibernate;
using NHibernate.Cfg;
using NHibernate.Criterion;
using NHibernate.Exceptions;
using SpotifyGenNHibernate.EN.Spotify;

namespace SpotifyGenNHibernate.CAD.Spotify
{
        public partial class TPVCAD : BasicCAD, ITPVCAD
        {
        public TPVCAD() : base ()
        {
        }

        public TPVCAD(ISession sessionAux) : base (sessionAux)
        {
        }



        public TPVEN ReadOIDDefault (int IdTPV)
        {
                TPVEN tPVEN = null;

                try
                {
                        SesssionInitializeTransaction ();
                        tPVEN = (TPVEN)session.Load (typeof(TPVEN),
                                IdTPV

                                );
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in TPVCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return tPVEN;
        }


        public int NuevoTPV (TPVEN tPV)
        {
                try
                {
                        SesssionInitializeTransaction ();
                        if (tPV.Usuario != null) {
                                tPV.Usuario = (SpotifyGenNHibernate.EN.Spotify.UsuarioEN)session.Load (typeof(SpotifyGenNHibernate.EN.Spotify.UsuarioEN), tPV.Usuario.Nombre);
                        }

                        session.Save (tPV);
                        SessionCommit ();
                }

                catch (Exception ex) {
                        SessionRollBack ();
                        if (ex is ModelException)
                                throw ex;
                        throw new DataLayerException ("Error in TPVCAD.", ex);
                }


                finally
                {
                        SessionClose ();
                }

                return tPV.IdTPV;
        }
        }
}
